<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="css/main.css" />
	  <link rel="stylesheet" type="text/css" href="../mobile/js/layer/css/layui.css" />
	  <script src="../mobile/js/jquery-1.9.1.js"></script>
	  <script src="../mobile/js/layer/layui.js"></script>
	  <script src="./js/common.js"></script>
	  
		<style>
			html,body{
				padding:0;
				margin:0;
				height:100%;
				width:100%;
			}
		</style>
		
	</head>
	
	<body>
		
		<div class="logininfo">
			<div class="loginbox">
				<form action="" method="get"  enctype='multipart/form-data'>
					<div class="loginmain">
						<table width="100%" cellspacing="0">
							<tr style="margin-bottom: 20px;">
								<td width="10%" >
									<i class="iconfont loginicon">&#xe654;</i>
								</td>
								<td width="90%">
									<input type="text" placeholder="请输入用户名" name="username" id="username" class="logininput" />
									<p class="prompt"></p>
								</td>
							</tr>
							
							<tr>
								<td width="10%" >
									<i class="iconfont loginicon" style="top: 15px;position: relative;">&#xe61c;</i>
								</td>
								<td width="90%">
									<input type="password" placeholder="请输入密码" name="password" id="password" class="logininput ma-to-30" />
								</td>
							</tr>
							
							<tr>
								<td colspan="2" align="center">
									<button type="button" onclick="getLogin()" class="loginbtn">登录</button>
								</td>
							</tr>
						</table>
					</div>
				</form>
			</div>
		</div>
		
	</body>
	
 
	
	<script>
	//首先验证是否登录
	$(function(){
	var geturl=url+"/admin/adminapi/loginRequest";
	$.ajax({
			type: 'get',
			dataType: "json",
			url: geturl,
			success: function (dete) {
				// console.log(dete);
				if(dete.code == 1){
					//表示已经登录
					window.location.href="index.html";
				}
			},error:function(data){
				console.log("请检查您的网络");
			}
		});
	});
	$('#username').mousemove(function () {
		$('#username').focus();
	});

	$('#password').mousemove(function () {
		$('#password').focus();
	});
	// 绑定键盘上的Enter键 start
	$('#password').bind('keyup',function(event){
		if(event.keyCode == '13'){
			getLogin();
		}
	})
	// 绑定键盘上的Enter键 end
	
	function getLogin(){
		var username = $('#username').val();
		var password = $('#password').val();

		if(username==""){
			alert("请输入登录账号");
			$('#username').focus();
			return false;
		}else if(password==""){
			alert("请输入登录密码");
			$('#username').focus();
			return false;
		}

		$.ajax({
			type: 'post',
			dataType: "json",
			url: url+"/admin/adminapi/adminlogin",
			data:{username:username,password:password},
			success: function (data) {
				// console.log(data);
				// return false;
				if (data.codes == 0) {
					layer.open({
						content: data.infomsg
			    	  });
				}
				if (data == 1) {
					window.location.href="index.html";
				}

			},error:function(data){
				console.log("请检查您的网络");
			}
		});

	}

		
	</script>
	
</html>
